import tkinter as tk
from view import *  # 菜单栏对应的各个子页面


class MainPage:
    def __init__(self, master=None):
        self.root = master  # 定义内部变量root
        self.root.geometry('%dx%d' % (850, 500))  # 设置窗口大小

        self.create_page()

    def create_page(self):
        self.main_frame = tk.Frame(self.root)  # 创建一个主 Frame 来管理所有页面
        self.main_frame.pack(fill=tk.BOTH, expand=True)

        menubar = tk.Menu(self.root)


        self.businessmen_page = BusinessmenFrame(self.main_frame)  # 将页面添加到主 Frame
        self.jiaocai_page = JiaocaiFrame(self.main_frame)
        self.students_page = StudentsFrame(self.main_frame)
        self.order_page = OrderFrame(self.main_frame)
        self.acceptance_page = AcceptanceFrame(self.main_frame)
        self.businessmen_page.pack(fill=tk.BOTH, expand=True)  # 默认显示数据录入界面

        menubar.add_command(label='书商', command=self.businessmen_data)
        menubar.add_command(label='教材', command=self.jiaocai_data)
        menubar.add_command(label='学生', command=self.students_data)
        menubar.add_command(label='订购', command=self.order_data)
        menubar.add_command(label='领取', command=self.acceptance_data)
        self.root['menu'] = menubar  # 设置菜单栏

    def businessmen_data(self):
        self.show_page(self.businessmen_page)

    def jiaocai_data(self):
        self.show_page(self.jiaocai_page)

    def students_data(self):
        self.show_page(self.students_page)

    def order_data(self):
        self.show_page(self.order_page)

    def acceptance_data(self):
        self.show_page(self.acceptance_page)

    def show_page(self, page):
        # 隐藏当前显示的所有页面
        self.businessmen_page.pack_forget()
        self.jiaocai_page.pack_forget()
        self.students_page.pack_forget()
        self.order_page.pack_forget()
        self.acceptance_page.pack_forget()
        # 显示选中的页面
        page.pack(fill=tk.BOTH, expand=True)


if __name__ == '__main__':
    root = tk.Tk()
    main_page = MainPage(root)
    root.mainloop()